<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <form action="" method="POST" enctype="multipart/form-data">
    <input id="file" type="file" name="oimg">
    <img src="" id="oimg" alt="">
    <button type="submit">上传</button>
  </form>
  <script>
    var file = document.getElementById('file');
    var oImg = document.getElementById('oimg');
    file.onchange = function(){
      // 获取上传文件控件 选择的文件 files 上传文件控件 保存了 选择文件
      /* 
      dataurl
      base64
      */
      console.log(this.files[0]);
      // 创建 fd
      var fd = new FileReader();
      fd.readAsDataURL(this.files[0]);
      fd.onload = function(){
        console.log(this.result);
        oImg.src = this.result;
      }
    }
  </script>
</body>
</html>